<?php abstract class sensors implements iFilter, iReconfigurable, iCycler {
	protected static $Dir = '.';
	protected static $Timeout = 150;
	public static function Reconfigure (array $Config) {
		if (array_key_exists ('dir', $Config)) {
			Out::I (Msg::ConfigGot, 'dir', $Dir = $Config ['dir']);
			if (is_dir ($Dir)) {
				if (is_writeable ($Dir)) {
					Out::I (Msg::ConfigApplied, 'dir', $Dir);
					self::$Dir = $Dir;
				} else Out::W (Msg::NotWriteable, $Dir);
			} else Out::W (Msg::NotADirectory, $Dir);
		} else Out::W (Msg::ConfigMiss, 'dir');
		if (array_key_exists ('timeout', $Config)) {
			Out::I (Msg::ConfigApplied, 'timeout', self::$Timeout = $Config ['timeout']);
		}
	}
	public static function Action (array $Line) {
		$Sensors = explode (' ', $Line ['message']);
		$Host = array_shift ($Sensors);
		file_exists ($Filename = self::$Dir.'/'.$Host.'.hb') or Out::W (Msg::HBNewHost, $Host);
		@touch ($Filename) or Out::W (Msg::TouchError, $Filename);
		foreach ($Sensors as $Sensor) {
			@list ($Sensor, $Data) = explode (',', $Sensor, 2);
			if (! class_exists ($Sensor)) {
				Out::W (Msg::ClassMissing, $Sensor);
				continue;
			}
			if (! HasInterface ($Sensor, 'iRRDTemplate')) {
				Out::W (Msg::DoesNotImplement, $Sensor, 'iRRDTemplate');
				continue;
			}
			call_user_func (array ($Sensor, 'Feed'), $Line ['seconds'], $Host, $Data);
		}
	}
	public static function Commit () {}
	public static function Cycle () {
		foreach (glob (self::$Dir.'/*.hb') as $Hostfile) if (is_readable ($Hostfile)) {
			$Host = basename ($Hostfile, '.hb');
			$Diff = time () - filemtime ($Hostfile);
			if ($Diff < 0) {
				Out::W (Msg::HBDiffNegative, $Host, -$Diff);
				touch ($Hostfile);
			} elseif ($Diff > self::$Timeout) {
				Out::W (Msg::HBTimedOut, $Host, $Diff);
				unlink ($Hostfile);
			}
		} else continue;
	}
} ?>